function sprintf() {
    var arg = arguments,
            str = arg[0] || '',
            i, n;
    for (i = 1, n = arg.length; i < n; i++) {
        str = str.replace(/%s/, arg[i]);
    }
    return str;
}
function assign_customerLinkman(id) {
    alert(1);
    $.get(_APP_ + "/CRM/CustomerLinkman/ajax_getLinkman", {
        customer_id: id
    }, function(data) {
        var _html = $("<select />");
        var _option;
        _html.addClass("span3");
        _html.attr("name", "customer_linkman_id");
        for (i = 0; i < data.length; i++) {
            _option = $("<option />");
            _option.attr("value", data[i].id)
            _option.text(data[i].contact);
            _html.append(_option);
        }
        $(".CustomerSelect").parent().find("select").remove();
        $(".CustomerSelect").after(_html);
    });
}

$(function() {
    if ($(".CustomerSelect")) {
        $(".CustomerSelect").autocomplete({
            source: _APP_ + "/CRM/Customer/ajax_getCustomers",
            minLength: 1,
            select: function(event, ui) {
                $("#customer_id").val(ui.item.id);
                assign_customerLinkman(ui.item.id);
            }
        });
    }
});

Array.prototype.in_array = function(e)
{
    for (i = 0; i < this.length; i++)
    {
        if (this[i] == e)
            return true;
    }
    return false;
}
Array.prototype.indexOf = function(val) {
    for (var i = 0; i < this.length; i++) {
        if (this[i] == val)
            return i;
    }
    return -1;
};
Array.prototype.remove = function(val) {
    var index = this.indexOf(val);
    if (index > -1) {
        this.splice(index, 1);
    }
};